clear all
set more off
	
global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"

use "Data\donor_level_persist_rep.dta",clear

keep if rank==1&family==0


	texdoc close 
	cap erase "$dir/Tables/Table4.tex"
	texdoc init "$dir/Tables/Table4.tex", force


	tex \begin{table}[h]
	tex \caption{Effects of contracts on next election donations (Non-family members)}\label{tab:contracts_donation}
	tex \centering
	tex \begin{tabular}{lHcc c Hcc c HHH} \hline
	*tex Outcome: & \multicolumn{3}{c}{Any race} && \multicolumn{3}{c}{Mayor} && \multicolumn{3}{c}{Only mayor} \\ \cline{2-4} \cline{6-8} \cline{10-12}
	tex Outcome: & \multicolumn{3}{c}{Any race} && \multicolumn{3}{c}{Mayor} && \\ \cline{2-4} \cline{6-8} 
	tex & (1) & (1) & (2) && (4) & (3) & (4) && (7) & (5) & (6) \\ \hline
	tex & & & & & & & & & & &\\
	
	
	
	replace b5=. if b2!=0
	
	*Model 1
	foreach x in donate_15any b5{
	
		*Summary statistics for the mean
		quietly: reg `x' contract sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_102 contraloria above_lim , vce(cluster muni_code)
		quietly sum `x' if e(sample)
			local mean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 
		
		*Regressions
		reg `x' contract sanc_before ilegal p_prop elec_exp pol_exp_d center rank_don_alt_all lcont_donor_102 contraloria above_lim , vce(cluster muni_code)
		
		local N_`x' : di %5.0f e(N)
		local R2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local b1_`x' : di %5.3f b[1,1]
		local se1_`x' : di %5.3f sqrt(v[1,1])
		local p_v_`x' :di %5.3f res[4,1]
		local uci_`x': di %5.3f res[6,1]
		local lci_`x': di %5.3f res[5,1]
		
		*T-statistics
		local t1_`x' = `b1_`x''/`se1_`x''
		local t1_`x' : di %5.3f  `t1_`x''
		
		
		*P-values
		local df : di `e(N)'-`e(k_absorb)'-`e(df_m)'-1
		scalar pval1_`x' = ttail(`df', abs(`t1_`x''))*2		


	
	
		*Reg with FE
		areg `x' contract rank_don_alt_all lcont_donor_102 contraloria above_lim if e(sample),absorb(muni_code) vce(cluster muni_code)
		
		local dN_`x' : di %5.0f e(N)
		local dR2_`x' : di %5.3f e(r2)
		
		matrix db = e(b)
		matrix dv = e(V)
		matrix dres=r(table)
		
		local db1_`x' : di %5.3f db[1,1]
		local dse1_`x' : di %5.3f sqrt(dv[1,1])
		local dp_v_`x' :di %5.3f dres[4,1]
		local duci_`x': di %5.3f dres[6,1]
		local dlci_`x': di %5.3f dres[5,1]
				
		*T-statistics
		local dt1_`x' = `db1_`x''/`dse1_`x''
		local dt1_`x' : di %5.3f  `dt1_`x''
		
		
		*P-values
		local df : di `e(N)'-`e(k_absorb)'-`e(df_m)'-1
		scalar dpval1_`x' = ttail(`df', abs(`dt1_`x''))*2


			
	}	

	tex  Contract & `ub1_donate_15any' & `b1_donate_15any' & `db1_donate_15any' && `ub1_b5' & `b1_b5' & `db1_b5' && `ub1_b3' & `b1_b3' & `db1_b3' \\
	tex  \ \ \ \ p-value & `up_v_donate_15any' & `p_v_donate_15any' & `dp_v_donate_15any' && `up_v_b5' & `p_v_b5' & `dp_v_b5' && `up_v_b3' & `p_v_b3' & `dp_v_b3' \\ 
	tex  \ \ \ \ CI 95\% & [`ulci_donate_15any',`uuci_donate_15any']& [`lci_donate_15any',`uci_donate_15any'] & [`dlci_donate_15any',`duci_donate_15any'] && [`ulci_b5',`uuci_b5'] & [`lci_b5',`uci_b5'] & [`dlci_b5',`duci_b5'] && [`ulci_b3',`uuci_b3'] & [`lci_b3',`uci_b3'] & [`dlci_b3',`duci_b3'] \\ \hline
	tex  % & (`use1_donate_15any') & (`se1_donate_15any') & (`dse1_donate_15any') && (`use1_b5') & (`se1_b5') & (`dse1_b5') && (`use1_b3') & (`se1_b3') & (`dse1_b3') \\ 	
	
	tex Observations & `uN_donate_15any' & `N_donate_15any' & `dN_donate_15any' && `uN_b5' & `N_b5' & `dN_b5' && `uN_b3' & `N_b3' & `dN_b3' \\
	tex Mean &  `mean_donate_15any' & `mean_donate_15any' &  `mean_donate_15any' && `mean_b5' & `mean_b5' &`mean_b5'&& `mean_b3' & `mean_b3' & `mean_b3' \\
	*tex Effect Mean(\%) & `fem1_donate_15any' & `fem1_b5' & `fem1_b3' \\
	tex Controls mayor& no & yes & no && no & yes &no && no & yes & no \\
	tex Controls donor& no & yes & yes && no & yes &yes && no & yes & yes \\
	tex Municipality FE & no & no & yes &&no & no & yes && no & no & yes \\ \hline
	tex \end{tabular}
	tex \parbox{150mm}{  \footnotesize{
	tex Ordinary least squares (OLS) estimates of the effect of receiving a contract on donating in the next election. The sample includes non-family donors to the mayor. `Controls mayor' denotes candidate's illegal registration of ID, being sanctioned by the Office of the Inspector General, elected posts, ran as candidate in past elections, party is not left-wing or right-wing, and non family donations as a fraction of campaign revenue. `Controls donor' denotes logged value of donation, donated above legal limit, sanctioned, and rank of donation among all family and non-family donors. Confidence intervals and p-values with clusters at the municipality level.
	tex }
	tex }
	tex \end{table}
	cap texdoc close 
	